<!DOCTYPE html>
<HTML>
<HEAD>
	<TITLE></TITLE>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" href="css/demo.css">
	<link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css">
	<script type="text/javascript" src="//www.heanny.cn/library/jquery/jquery-3.3.1.js"></script>
	<script type="text/javascript" src="js/ztree/jquery.ztree.core.js"></script>
	<script>

		function ShowFileTree(ReData) {
			var zTree = [];
			$.each(ReData, function (key, value) {
				if (typeof value == 'string') {
					zTree.push({ name: value,url:'download/'+value})
				} else if (typeof value == 'object') {
					zTree.push({ name: key, children: ShowFileTreeChild(value)})
				}else{
console.log(key,value)
				}
			});
			return zTree;

		}
		function ShowFileTreeChild(ReData) {
			var zTree = [];
			$.each(ReData, function (key, value) {
				if (typeof value == 'string') {
					zTree.push({ name: value,url:'download/'+value})
				} else if (typeof value == 'object') {
					zTree.push({ name: key, children: ShowFileTreeChild(value)})
				}else{
					console.log(key,value)
				}
			});
			return zTree;

		}
	</script>

</HEAD>
<body>
<div class="zTreeDemoBackground left">

	<ul id="treeDemoZ" class="ztree"></ul>
</div>
</body>


<script>
	$(function () {
		var setting = {
			view: {
				selectedMulti: false
			}
		};
		$.post('api/read.php', function (req) {
			var ReData = JSON.parse(req);
			var zTree = [];
			if (ReData.code == 1) {
				$(document).ready(function () {
					$.fn.zTree.init($("#treeDemoZ"), setting, ShowFileTree(ReData.data));
				});
			}
		})
	})
</script>
</html>